package xiaoyang.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xiaoyang.dao.AppInfoMapper;
import xiaoyang.dao.VersionMapper;
import xiaoyang.pojo.AppInfo;
import xiaoyang.pojo.AppVersion;
import xiaoyang.service.AppInfoService;


import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class AppInfoServiceImpl implements AppInfoService {
    @Resource
    private AppInfoMapper appInfoMapper;
    @Resource
    private VersionMapper versionMapper;
    @Override
    /**
     *管理者页面显示
     */
    public List<AppInfo> getInfoAll(String softwareName, Integer flatformId, Integer categoryLevel1, Integer categoryLevel2, Integer categoryLevel3, Integer pageIndex, Integer pageSize) {

        List<AppInfo> infoAll = appInfoMapper.getInfoAll(softwareName, flatformId, categoryLevel1, categoryLevel2, categoryLevel3, pageIndex, pageSize);
        return infoAll;
    }

    @Override
    /**
     * 管理者页面显示数量
     */
    public int appInfoCount(String softwareName, Integer flatformId, Integer categoryLevel1, Integer categoryLevel2, Integer categoryLevel3) {
        return appInfoMapper.appInfoCount(softwareName, flatformId, categoryLevel1, categoryLevel2, categoryLevel3);
    }

    @Override
    /**
     * 开发者显示
     */
    public PageInfo<AppInfo> getDevInfoAll(String softwareName, Integer flatformId, Integer status, Integer categoryLevel1, Integer categoryLevel2, Integer categoryLevel3,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<AppInfo> pageInfo = new PageInfo<>(appInfoMapper.getDevInfoAll(softwareName, flatformId, status, categoryLevel1, categoryLevel2, categoryLevel3));
        return pageInfo;
    }

    /**
     * 新增手游
     * @param appInfo
     * @return
     */
    @Override
    public boolean appInfoAdd(AppInfo appInfo) {

        return appInfoMapper.appInfoAdd(appInfo);
    }

    /**
     * 查询APKName是否存在
     * @param APKName
     * @return
     */
    @Override
    public AppInfo getApkName(String APKName) {
        return appInfoMapper.getApkName(APKName);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public AppInfo getIdAll(Integer id) {
        return appInfoMapper.getIdAll(id);
    }

    /**
     * 修改手游信息
     * @param appInfo

     * @return
     */
    @Override
    public boolean update(AppInfo appInfo) {
        return appInfoMapper.update(appInfo);
    }

    /**
     * 更新版本信息
     * @param appInfo
     * @return
     */
    @Override
    public boolean updateVersion(AppInfo appInfo) {
        return appInfoMapper.updateVersion(appInfo);
    }

    /**
     * view
     * @param id
     * @return
     */
    @Override
    public AppInfo getAppInfoId(Integer id) {
        return appInfoMapper.getAppInfoId(id);
    }

    /**
     * 删除手游
     * @param id
     * @return
     */
    @Override
    public boolean devDel(Integer id) {
        return appInfoMapper.devDel(id);
    }

    /**
     * 下架
     * @param id
     * @return
     */
    @Override
    public boolean xj(Integer id) {
        return appInfoMapper.xj(id);
    }

    /**
     * 上架
     * @param id
     * @return
     */
    @Override
    public boolean sj(Integer id) {
        return appInfoMapper.sj(id);
    }

    /**
     * 审核通过
     * @return
     */
    @Override
    public boolean auditPass(Integer id,Integer version) {
        return appInfoMapper.auditPass(id,version);
    }

    /**
     * 审核不通过
     * @return
     */
    @Override
    public boolean auditNoPass(Integer id,Integer version) {
        return appInfoMapper.auditNoPass(id,version);
    }

    @Override
    public boolean upAuditNoPass(Integer id) {
        return appInfoMapper.upAuditNoPass(id);
    }



    /**
     * 查询版本
     * @param appId
     * @return
     */
    @Override
    public List<AppVersion> getVersion(Integer appId) {
        return versionMapper.getVersion(appId);
    }

    @Override
    public boolean versionAdd(AppVersion appVersion) {
        return versionMapper.versionAdd(appVersion);
    }

    /**
     * 修改版本
     * @param appVersion
     * @return
     */
    @Override
    public boolean upVersion(AppVersion appVersion) {
        return versionMapper.upVersion(appVersion);
    }

    @Override
    public AppVersion appVersionId(Integer id) {
        AppVersion appVersion = versionMapper.appVersionId(id);
        return appVersion;
    }

    /**
     * 删除版本
     * @param appId
     * @return
     */
    @Override
    public boolean verDel(Integer appId) {
        return versionMapper.verDel(appId);
    }

    /**
     * 查询手游版本数量
     * @param appId
     * @return
     */
    @Override
    public int appIdCount(Integer appId) {
        return versionMapper.appIdCount(appId);
    }

    /**
     * 下载次数
     * @param id
     * @return
     */
    @Override
    public int updateDownloads(Integer id) {
        return versionMapper.updateDownloads(id);
    }

    @Override
    public boolean upImg(Integer id) {
        return appInfoMapper.upImg(id);
    }

    @Override
    public boolean upApk(Integer id) {
        return versionMapper.upApk(id);
    }
}